package com.shouhuobao.take.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;

/**
 * Created by joker on 2017/6/5.
 */

public class DateUtils {
    /**
     * 创建日期格式 yyyy.MM.dd
     */
    private static ThreadLocal<DateFormat> DATE_FORMAT_THREAD_LOCAL = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {
            return new SimpleDateFormat("yyyy.MM.dd");
        }
    };

    /**
     * 获取日期格式DateFormat为yyyy.MM.dd
     *
     * @return
     */
    public static DateFormat getDateFormat() {
        return DATE_FORMAT_THREAD_LOCAL.get();
    }

    /**
     * 创建日期格式 yyyy.MM
     */
    private static ThreadLocal<DateFormat> DATE_FORMAT_THREAD_LOCALYYYYMM = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {
            return new SimpleDateFormat("yyyy.MM");
        }
    };

    /**
     * 获取日期格式DateFormat为yyyy.MM
     *
     * @return
     */
    public static DateFormat getDateYYYYMMFormat() {
        return DATE_FORMAT_THREAD_LOCALYYYYMM.get();
    }
    /**
     * 创建日期格式 yyyy.MM
     */
    private static ThreadLocal<DateFormat> DATE_FORMAT_THREAD_LOCALMMDD = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {
            return new SimpleDateFormat("MM.dd");
        }
    };

    /**
     * 获取日期格式DateFormat为yyyy.MM
     *
     * @return
     */
    public static DateFormat getDateMMDDFormat() {
        return DATE_FORMAT_THREAD_LOCALMMDD.get();
    }
    /**
     * 创建时间格式 HH:mm
     */
    private static ThreadLocal<DateFormat> DATE_FORMAT_THREAD_LOCALHHmm = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {
            return new SimpleDateFormat("HH:mm");
        }
    };
    /**
     * 获取日期格式DateFormat为HH:mm
     *
     * @return
     */
    public static DateFormat getTimeHHmmFormat() {
        return DATE_FORMAT_THREAD_LOCALHHmm.get();
    }

    /**
     * 创建时间格式 yyyy-MM-dd HH:mm:ss
     */
    private static ThreadLocal<DateFormat> DATE_FORMAT_THREAD_LOCALYMDHMS = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {
            return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        }
    };
    /**
     * 获取日期格式DateFormat为 yyyy-MM-dd HH:mm:ss
     *
     * @return
     */
    public static DateFormat getTimeYMDHMSFormat() {
        return DATE_FORMAT_THREAD_LOCALYMDHMS.get();
    }
}
